package com.hnqcgc.controller;

import com.hnqcgc.service.IProductService;
import com.hnqcgc.service.ProductServiceImpl;
import com.hnqcgc.vo.TProduct;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/productInfoServlet")
public class ProductInfoServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //获取指定商品的ID
        int pid = Integer.parseInt(req.getParameter("pid"));

        //调用业务层方法，获取商品详情
        IProductService productService=new ProductServiceImpl();
        TProduct p=null;
        try {
            p = productService.getProductInfoById(pid);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        //存储在服务器端
        HttpSession session = req.getSession();
        session.setAttribute("good",p);
        //转发
        req.getRequestDispatcher("ProductDetail.jsp").forward(req,resp);


    }
}
